import React, { Component } from 'react';
import { View, Text, Image,TouchableOpacity } from 'react-native';

var Dimensions = require('Dimensions');
var { width, height } = Dimensions.get('window');

class AttachmentUpload extends Component {

    render() {
        let rowData = this.props.rowData;

        var  imgitems = [];

        if(rowData.imgs.length > 6){

            for(var i = 0; i < 6; i++){

                imgitems.push(
                    rowData.imgs[i]
                )
            }

        }else{
            imgitems = rowData.imgs;
        }

        return (
            <View style={{ padding: 10, paddingBottom: 0, backgroundColor: 'white' }}
            pointerEvents = {this.props.status === '1'? 'none':'auto'}
            >
                <View flexDirection='row' style={{ flex: 1, alignItems: 'center', marginBottom: 10 }}>
                    <Image source={{ uri: rowData.attachment }}
                        style={{ marginRight: 10, width: 25, height: 25 }}
                    />
                    <Text>上传附件</Text>
                    <View style={{ flex: 1, justifyContent: 'center' }}>
                        <Text style={{ textAlign: 'right', marginRight: 10 }}>可上传6张图片（{rowData.progressText}）</Text>
                    </View>
                </View>
                <View style={{ flexDirection: 'row', flexWrap: 'wrap', }}>{
                    imgitems.map(t => <TouchableOpacity key={t.id} activeOpacity={0.5}
                        onLongPress={() => this.props.imgLongPregress(t)}
                        onPress={() => this.props.imgClick(t)}
                        style={{ backgroundColor: '#e8e8e8', width: (width - 50) / 3.0, 
                        height: (width - 50) / 3.0, marginBottom: 10, marginRight: 10,justifyContent:'center',alignItems:'center'}}
                    >

                    <Image source={{uri:t.imgName}}
                     style={{width:t.id==='0'? 24 :(width - 50) / 3.0, height: t.id==='0'? 18 :(width - 50) / 3.0,}}
                    />
                    </TouchableOpacity>)
                }
                </View>
            </View>
        );
    }


}

export default AttachmentUpload;
